package com.qire.manhua.controller;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

import com.qire.common.basic.ObjectUtil;
import com.qire.common.basic.StringUtil;
import com.qire.common.support.base.EventController;
import com.qire.common.widget.adapter.auto.AutoVariable;
import com.qire.manhua.BR;
import com.qire.manhua.activity.FriendPaidActivity;
import com.qire.manhua.databinding.ActivityFriendPaidBinding;
import com.qire.manhua.model.entity.ShareInfo;
import com.qire.manhua.model.enumeration.ShareType;
import com.qire.manhua.model.viewModel.impl.FriendPaidViewModel;
import com.qire.manhua.model.viewModel.impl.FriendPaidViewModel.FriendPaidItemViewModel;
import com.qire.other.share.ShareActionFactory;

import java.util.HashMap;

public class FriendPaidController extends EventController<FriendPaidActivity> implements AutoVariable {

    private FriendPaidViewModel viewModel;

    public FriendPaidController(@NonNull FriendPaidActivity activity) {
        super(activity);
    }

    @Override
    protected void bindView() {
        ActivityFriendPaidBinding viewDataBinder = owner.viewDataBinder();
        viewDataBinder.setFriendPaidController(this);
    }

    @Override
    public void bindVariable(ViewDataBinding viewBind) {
        viewBind.setVariable(BR.friendPaidController,this);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(FriendPaidViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /*************************************************************************************************************************/

    public void backBtnOnclick(View view) {
        owner.onBackPressed();
    }

    public void waresLayoutOnClick(View view) {
        FriendPaidItemViewModel itemViewModel = ObjectUtil.as(view.getTag(), FriendPaidItemViewModel.class);
        if(ObjectUtil.nonNull(itemViewModel)) {
            itemViewModel.toggle();
        }
        viewModel.goFriendPaidPanel();
    }

    public void shareBtnOnClick(View view) {
        HashMap<String, Object> shareMap = new HashMap<>();

        ShareInfo shareInfo = viewModel.shareInfo();
        shareMap.put("shareType", 2);//Platform.SHARE_IMAGE);
//        shareMap.put("ShareType", Platform.SHARE_WEBPAGE);
        shareMap.put("title", shareInfo.title);//测试分享的标题
        shareMap.put("titleUrl", shareInfo.urlPage);// 标题的超链接
        shareMap.put("text", shareInfo.content);//测试分享的文本
        shareMap.put("imageUrl", StringUtil.appendTimestampTo(shareInfo.urlImage));//测试分享的图片
        shareMap.put("site", shareInfo.title);//发布分享的网站名称
        shareMap.put("siteUrl", shareInfo.urlPage);//发布分享网站的地址

        ShareActionFactory.create(ShareType.WECHAT.shareName).doShareAction(shareMap);
    }

}
